<template>
	<view>
		
		<!-- 患者信息 -->
		<view class="testHeight" :style="{
			'background': `linear-gradient(150deg, ${sex(rx_info.sex)} 5%, #ffffff 10%, #ffffff 90%, ${sex(rx_info.sex)} 95%)`,
			'border-radius': `${borderRadius}rpx`,
			'border-radius': '20rpx'
		}">
			<view style="margin: 10rpx 20rpx 10rpx 20rpx">
				{{ rx_info.name }} - {{ rx_info.sex }} - {{ rx_info.age }}岁 - {{ rx_info.mobile }}
			</view>
		</view>
		
		<!-- 手写板 -->
		<view id="positionInfo" :style="{'width': '100%', 'height': `${window.height}px`}">
		    <th-autograph
			ref="getAutoData"
			@rxBack='rxBacks'
			@addHeight='addHeights'
		    :is-download="false" 
		    @submit="getFile" 
		    canvas-id="autograph">
		    </th-autograph>
		</view>
	</view>
</template>

<script>
    import thAutograph from "@/pages/medic/create_rx/components/th-autograph/th-autograph.vue"
    export default {
		name:"rx",
        components:{
            thAutograph
        },
		data() {
			return {
				rx_info: {},
				window: {
					height: 0,
					width: 0,
					bTop: 0,	// 手写板到顶部的距离
				}
			};
		},
		created() {
			
			var _this = this
			
			// 手写板到顶部的距离
			const pInfo = uni.createSelectorQuery().in(_this);
			pInfo
			  .select("#positionInfo")
			  .boundingClientRect((data) => {
				  _this.window.bTop = data.top
			  })
			  .exec();

			// 获取底部安全距离
			const query = uni.createSelectorQuery().in(_this);
			query
			  .select(".testHeight")
			  .boundingClientRect((data) => {
				  // 获取屏幕高度信息设置手写板的高度
				  uni.getSystemInfo({
				  	success(res) {
				  		_this.window.width = res.windowWidth	// 窗口宽度
						// 判断是否需要重新绘制
						const rx_info_canvas = _this.$store.state.rx.canvas
						if (rx_info_canvas.code === 1) {
							_this.window.height = rx_info_canvas.hight * 1.05
						} else {
							_this.window.height = res.windowHeight - _this.window.bTop - 70		// 窗口高度
						}
				  	}
				  })
			  })
			  .exec();
			  
			_this.rx_info = _this.$store.state.rx		// 获取缓存数据
			
		},
        methods:{
			rxBacks(RxPath) {
				this.tempCacheRxData(RxPath)
				this.$emit('rxBack')
			},
			sex(x) {
				if (x === '女') {
					return '#d27881 '
				}
				return '#5491f8'
			},
			// 增加手写板高度
			addHeights() {
				console.log('设置手写板高度')
				this.window.height = this.window.height * 1.5
			},
            getFile(RxPath){
				this.tempCacheRxData(RxPath)
				this.$emit("rxNext")
				console.log('患者信息', this.rx_info)
            },
			tempCacheRxData(RxPath) {
				this.rx_info.canvas.code = 1
				this.rx_info.canvas.tempImagePath = RxPath
				this.rx_info.canvas.width = this.window.width
				this.rx_info.canvas.hight = this.window.height
				this.$store.dispatch('set_rx', this.rx_info)	// 缓存数据
			}
        }
    }
</script>